package co.edu.udea.iw.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


import co.edu.udea.iw.dao.Tipo_SolicitudDAO;
import co.edu.udea.iw.dto.tipo_solicitud;
import co.edu.udea.iw.exception.waDaoException;

public class Tipo_SolicitudDAOHibernate extends HibernateDaoSupport implements Tipo_SolicitudDAO {

	@Override
	public tipo_solicitud insertar(tipo_solicitud ts) throws waDaoException {
		Transaction tx = null;
		Session session = null;
		try {
			session = getSession();
			tx = session.beginTransaction();
			session.save(ts);
			tx.commit();

		} catch (HibernateException e) {

			throw new waDaoException(e);
		} finally {
			// session.close();
		}
		return ts;
	}

	@Override
	public tipo_solicitud modificar(tipo_solicitud ts) throws waDaoException {
		Transaction tx = null;
		Session session = null;
		try {
			session = getSession();
			tx = session.beginTransaction();
			session.update(ts);
			tx.commit();

		} catch (HibernateException e) {

			throw new waDaoException(e);
		} finally {
			session.close();
		}
		return ts;
	}

	@Override
	public void eliminar(tipo_solicitud ts) throws waDaoException {
		Transaction tx = null;
		Session session = null;
		try {
			session = getSession();
			tx = session.beginTransaction();

			session.delete(ts);
			tx.commit();

		} catch (HibernateException e) {

			throw new waDaoException(e);
		} finally {
			session.close();
		}

	}

	@Override
	public List<tipo_solicitud> Consultar() throws waDaoException {
		List<tipo_solicitud> tsds = null;
		Session session = null;
		try {
			session = getSession();

			Criteria criteria = session.createCriteria(tipo_solicitud.class);
			tsds = criteria.list();
		} catch (HibernateException e) {

			throw new waDaoException(e);
		} 
		return tsds;
	}

	@Override
	public tipo_solicitud obtener(String tipo) throws waDaoException {
		tipo_solicitud ts = null;
		Session session = null;
		try {
			session = getSession();
			ts = (tipo_solicitud) session.load(tipo_solicitud.class, tipo);
		} catch (HibernateException e) {

			throw new waDaoException(e);
		} finally {
			session.close();
		}
		return ts;
	}

}
